import numpy as np
import pandas as pd
import xarray as xr
from matplotlib import pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
ds = xr.open_dataset('NOAA_NCDC_ERSST_v3b_SST.nc', engine = 'netcdf4')
ds_region = ds.sel(lon = slice(190, 240), lat = slice(-5, 5))
group_data = ds_region.sst.groupby('time.month')
sst_anom = group_data - group_data.mean(dim = 'time')
sst_anom
<xarray.DataArray 'sst' (time: 684, lat: 5, lon: 26)>
array([[[-0.43157768, -0.41846275, -0.39795303, ..., -0.2116642 ,
-0.23776245, -0.24401474],
[-0.41259003, -0.4067192 , -0.3875141 , ..., -0.52064896,
-0.5346451 , -0.51997185],
[-0.40932274, -0.39743805, -0.36237717, ..., -0.6373882 ,
-0.6171951 , -0.583725 ],
[-0.4140854 , -0.37909317, -0.3215618 , ..., -0.43292618,
-0.38404274, -0.3352623 ],
[-0.5043678 , -0.43894005, -0.3710251 , ..., -0.17453575,
-0.11044502, -0.06918144]],
[[-0.5374584 , -0.52739716, -0.50823593, ..., -0.40254593,
-0.44382668, -0.45287704],
[-0.55093956, -0.539135 , -0.51673317, ..., -0.6660595 ,
-0.7127285 , -0.710968 ],
[-0.61242104, -0.5959244 , -0.5572338 , ..., -0.7235069 ,
-0.7326374 , -0.73106194],
[-0.6798363 , -0.6483364 , -0.5889931 , ..., -0.5397434 ,
-0.50793266, -0.49977684],
[-0.7830448 , -0.7286701 , -0.6683655 , ..., -0.33967972,
...
-0.2555828 , -0.13972664],
[-0.989378 , -1.0497723 , -1.0954857 , ..., -0.86087227,
-0.7690697 , -0.65498734],
[-1.1887245 , -1.252285 , -1.3029232 , ..., -1.0460625 ,
-0.9661274 , -0.8785801 ],
[-1.002367 , -1.0756893 , -1.1325111 , ..., -0.7207298 ,
-0.6597252 , -0.5900669 ],
[-0.5770798 , -0.65514374, -0.72174263, ..., -0.4353485 ,
-0.36265945, -0.28103828]],
[[-0.3578701 , -0.41542053, -0.47110367, ..., -0.2400589 ,
-0.1464405 , -0.03788376],
[-0.7678585 , -0.83501625, -0.9024124 , ..., -0.727829 ,
-0.61603355, -0.48027992],
[-0.96187973, -1.0445309 , -1.1224213 , ..., -0.9327831 ,
-0.81235695, -0.6655674 ],
[-0.82112694, -0.9206734 , -1.0085506 , ..., -0.6531601 ,
-0.5626869 , -0.4374504 ],
[-0.4864292 , -0.5823746 , -0.6702862 , ..., -0.36221695,
-0.30041504, -0.1987915 ]]], dtype=float32)
Coordinates:
* lat (lat) float32 -4.0 -2.0 0.0 2.0 4.0
* lon (lon) float32 190.0 192.0 194.0 196.0 ... 234.0 236.0 238.0 240.0
* time (time) datetime64[ns] 1960-01-15 1960-02-15 ... 2016-12-15
month (time) int64 1 2 3 4 5 6 7 8 9 10 11 ... 2 3 4 5 6 7 8 9 10 11 12array([[[-0.43157768, -0.41846275, -0.39795303, ..., -0.2116642 ,
-0.23776245, -0.24401474],
[-0.41259003, -0.4067192 , -0.3875141 , ..., -0.52064896,
-0.5346451 , -0.51997185],
[-0.40932274, -0.39743805, -0.36237717, ..., -0.6373882 ,
-0.6171951 , -0.583725 ],
[-0.4140854 , -0.37909317, -0.3215618 , ..., -0.43292618,
-0.38404274, -0.3352623 ],
[-0.5043678 , -0.43894005, -0.3710251 , ..., -0.17453575,
-0.11044502, -0.06918144]],
[[-0.5374584 , -0.52739716, -0.50823593, ..., -0.40254593,
-0.44382668, -0.45287704],
[-0.55093956, -0.539135 , -0.51673317, ..., -0.6660595 ,
-0.7127285 , -0.710968 ],
[-0.61242104, -0.5959244 , -0.5572338 , ..., -0.7235069 ,
-0.7326374 , -0.73106194],
[-0.6798363 , -0.6483364 , -0.5889931 , ..., -0.5397434 ,
-0.50793266, -0.49977684],
[-0.7830448 , -0.7286701 , -0.6683655 , ..., -0.33967972,
...
-0.2555828 , -0.13972664],
[-0.989378 , -1.0497723 , -1.0954857 , ..., -0.86087227,
-0.7690697 , -0.65498734],
[-1.1887245 , -1.252285 , -1.3029232 , ..., -1.0460625 ,
-0.9661274 , -0.8785801 ],
[-1.002367 , -1.0756893 , -1.1325111 , ..., -0.7207298 ,
-0.6597252 , -0.5900669 ],
[-0.5770798 , -0.65514374, -0.72174263, ..., -0.4353485 ,
-0.36265945, -0.28103828]],
[[-0.3578701 , -0.41542053, -0.47110367, ..., -0.2400589 ,
-0.1464405 , -0.03788376],
[-0.7678585 , -0.83501625, -0.9024124 , ..., -0.727829 ,
-0.61603355, -0.48027992],
[-0.96187973, -1.0445309 , -1.1224213 , ..., -0.9327831 ,
-0.81235695, -0.6655674 ],
[-0.82112694, -0.9206734 , -1.0085506 , ..., -0.6531601 ,
-0.5626869 , -0.4374504 ],
[-0.4864292 , -0.5823746 , -0.6702862 , ..., -0.36221695,
-0.30041504, -0.1987915 ]]], dtype=float32)array([-4., -2., 0., 2., 4.], dtype=float32)
array([190., 192., 194., 196., 198., 200., 202., 204., 206., 208., 210., 212.,
214., 216., 218., 220., 222., 224., 226., 228., 230., 232., 234., 236.,
238., 240.], dtype=float32)array(['1960-01-15T00:00:00.000000000', '1960-02-15T00:00:00.000000000',
'1960-03-15T00:00:00.000000000', ..., '2016-10-15T00:00:00.000000000',
'2016-11-15T00:00:00.000000000', '2016-12-15T00:00:00.000000000'],
dtype='datetime64[ns]')array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4,
...
10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12])time = pd.date_range(start = '1960-01', periods = 684, freq = 'm')
plt.figure(figsize = (16, 9))
plt.plot(time, sst_anom, color = 'k')
plt.title('SST Anomaly in Nino 3.4 Region (5N-5S, 120-170W)',fontsize = 18)
plt.xlabel('Year', fontsize = 14)
plt.ylabel('Anomaly in Degrees C', fontsize = 14)
plt.ylim(-3, 3)
plt.grid(linestyle = '--', linewidth = 0.3, alpha = 0.5, color = 'k')
plt.hlines(y = 0.5, xmin = time[0], xmax = time[-1], color = 'r', linestyles = '--', lw = 0.5, label = 'EI Nino Threshold')
plt.hlines(y = -0.5, xmin = time[0], xmax = time[-1], color = 'b', linestyles = '--', lw = 0.5, label = 'La Nina Threshold')
plt.hlines(y = 0, xmin = time[0], xmax = time[-1], color = 'k', linestyles = 'solid', lw = 1, label = '3 mth running mean')
plt.legend(loc = 'best', fontsize = 12)
plt.fill_between(time, 0, sst_anom, where = (sst_anom > 0), color = 'r')
plt.fill_between(time, 0, sst_anom, where = (sst_anom < 0), color = 'b')
plt.show()
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) /var/folders/qy/ngsg7cz10ys7fn_5n46kknmr0000gn/T/ipykernel_9572/2393172653.py in <module> 2 3 plt.figure(figsize = (16, 9)) ----> 4 plt.plot(time, sst_anom, color = 'k') 5 plt.title('SST Anomaly in Nino 3.4 Region (5N-5S, 120-170W)',fontsize = 18) 6 plt.xlabel('Year', fontsize = 14) ~/miniconda3/envs/ese5023/lib/python3.9/site-packages/matplotlib/pyplot.py in plot(scalex, scaley, data, *args, **kwargs) 3017 @_copy_docstring_and_deprecators(Axes.plot) 3018 def plot(*args, scalex=True, scaley=True, data=None, **kwargs): -> 3019 return gca().plot( 3020 *args, scalex=scalex, scaley=scaley, 3021 **({"data": data} if data is not None else {}), **kwargs) ~/miniconda3/envs/ese5023/lib/python3.9/site-packages/matplotlib/axes/_axes.py in plot(self, scalex, scaley, data, *args, **kwargs) 1603 """ 1604 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D) -> 1605 lines = [*self._get_lines(*args, data=data, **kwargs)] 1606 for line in lines: 1607 self.add_line(line) ~/miniconda3/envs/ese5023/lib/python3.9/site-packages/matplotlib/axes/_base.py in __call__(self, data, *args, **kwargs) 313 this += args[0], 314 args = args[1:] --> 315 yield from self._plot_args(this, kwargs) 316 317 def get_next_color(self): ~/miniconda3/envs/ese5023/lib/python3.9/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs, return_kwargs) 502 f"have shapes {x.shape} and {y.shape}") 503 if x.ndim > 2 or y.ndim > 2: --> 504 raise ValueError(f"x and y can be no greater than 2D, but have " 505 f"shapes {x.shape} and {y.shape}") 506 if x.ndim == 1: ValueError: x and y can be no greater than 2D, but have shapes (684,) and (684, 5, 26)
You can modify the code as the following. So, two points were deducted.
time = pd.date_range(start = '1960-01', periods = 684, freq = 'm')
sst_anom_cal = sst_anom.mean(dim=['lat','lon'])
plt.figure(figsize = (16, 9))
plt.plot(time, sst_anom_cal, color = 'k')
plt.title('SST Anomaly in Nino 3.4 Region (5N-5S, 120-170W)',fontsize = 18)
plt.xlabel('Year', fontsize = 14)
plt.ylabel('Anomaly in Degrees C', fontsize = 14)
plt.ylim(-3, 3)
plt.grid(linestyle = '--', linewidth = 0.3, alpha = 0.5, color = 'k')
plt.hlines(y = 0.5, xmin = time[0], xmax = time[-1], color = 'r', linestyles = '--', lw = 0.5, label = 'EI Nino Threshold')
plt.hlines(y = -0.5, xmin = time[0], xmax = time[-1], color = 'b', linestyles = '--', lw = 0.5, label = 'La Nina Threshold')
plt.hlines(y = 0, xmin = time[0], xmax = time[-1], color = 'k', linestyles = 'solid', lw = 1, label = '3 mth running mean')
plt.legend(loc = 'best', fontsize = 12)
plt.fill_between(time, 0, sst_anom_cal, where = (sst_anom_cal > 0), color = 'r')
plt.fill_between(time, 0, sst_anom_cal, where = (sst_anom_cal < 0), color = 'b')
plt.show()
import numpy as np
import pandas as pd
import xarray as xr
from matplotlib import pyplot as plt
import nc_time_axis
get_ipython().run_line_magic('matplotlib', 'inline')
ds = xr.open_dataset("CERES_EBAF-TOA_200003-201701.nc", engine = 'netcdf4')
fig, axes = plt.subplots(2, 2, figsize = (10, 6), sharex = False, sharey = False, dpi = 400)
ds.toa_lw_all_mon.mean('time').plot(ax = axes[0, 0])
ds.toa_sw_all_mon.mean('time').plot(ax = axes[0, 1])
ds.solar_mon.mean('time').plot(ax = axes[1, 0])
ds.toa_net_all_mon.mean('time').plot(ax = axes[1, 1])
axes[0,0].set_title('TOA longwave', fontsize = 14)
axes[0,1].set_title('TOA shortwave', fontsize = 14)
axes[1,0].set_title('Solar radiation', fontsize = 14)
axes[1,1].set_title('Netflux', fontsize = 14)
plt.tight_layout()
da_netflux = ds.solar_mon - ds.toa_lw_all_mon - ds.toa_sw_all_mon
da_netflux.mean('time').plot(figsize = (8, 5))
plt.title('Netflux')
Text(0.5, 1.0, 'Netflux')
weights = np.cos(np.deg2rad(ds.lat))
weighted_solar = ds.solar_mon.weighted(weights)
weighted_lw = ds.toa_lw_all_mon.weighted(weights)
weighted_sw = ds.toa_sw_all_mon.weighted(weights)
print(weighted_solar.mean(dim = ('lon', 'lat','time')).values)
print(weighted_lw.mean(dim = ('lon', 'lat','time')).values)
print(weighted_sw.mean(dim = ('lon', 'lat','time')).values)
340.28326598091286 240.26691846331997 99.13806041149408
weighted_net = ds.toa_net_all_mon.weighted(weights)
R = 6371393
pi = np.pi
weighted_lat = 4*pi*R**2*weights/180
total_amount = weighted_net.mean(dim='lon') * weighted_lat
total_amount.transpose().plot(figsize=(8, 5))
plt.title('Net radiation in each 1-degree latitude band', fontsize = 14)
plt.tight_layout()
It should not be correct for using .mean(dim='lon'). I modified the code as follow. 1 point were deducted for 2.3.
weighted_net = ds.toa_net_all_mon.weighted(weights)
R = 6371393
pi = np.pi
weighted_lat = pi**2*R**2*weights/180**2
total_amount = weighted_net.sum(dim='lon') * weighted_lat
total_amount.transpose().plot(figsize=(8, 5))
plt.title('Net radiation in each 1-degree latitude band', fontsize = 14)
plt.tight_layout()
cldarea = ds.cldarea_total_daynight_mon.mean(dim='time').values
fig, axes = plt.subplots(2, 2, figsize=(16, 9), dpi = 400)
ds.toa_lw_all_mon.mean(dim='time').where(cldarea >= 75).plot(ax=axes[0, 0])
ds.toa_sw_all_mon.mean(dim='time').where(cldarea >= 75).plot(ax=axes[0, 1])
ds.toa_lw_all_mon.mean(dim='time').where(cldarea <= 25).plot(ax=axes[1, 0])
ds.toa_sw_all_mon.mean(dim='time').where(cldarea <= 25).plot(ax=axes[1, 1])
axes[0, 0].set_title('high cloud area outgoing longwave', fontsize = 14)
axes[0, 1].set_title('high cloud area outgoing shortwave', fontsize = 14)
axes[1, 0].set_title('low cloud area outgoing longwave', fontsize = 14)
axes[1, 1].set_title('low cloud area outgoing shortwave', fontsize = 14)
Text(0.5, 1.0, 'low cloud area outgoing shortwave')
After our three TAs discussed about question 2.4 and 2.5. We think that's more proper to select radiation by cloud condition and then calculate mean values. That's because radiation values are affected by cloud condition at that moment, not by the mean conditions. So, 1 point was deducted. And I also modified your code as follow, please think more.
## By HUANG Hao
# Create Figure and Subplots
fig,axes = plt.subplots(2,2,figsize=(16,8),dpi=500)
# Plot each axes
ds.toa_lw_all_mon.where(ds.cldarea_total_daynight_mon >= 75).mean(dim='time').plot(ax=axes[0,0])
ds.toa_sw_all_mon.where(ds.cldarea_total_daynight_mon >= 75).mean(dim='time').plot(ax=axes[0,1])
ds.toa_lw_all_mon.where(ds.cldarea_total_daynight_mon <= 25).mean(dim='time').plot(ax=axes[1,0])
ds.toa_sw_all_mon.where(ds.cldarea_total_daynight_mon <= 25).mean(dim='time').plot(ax=axes[1,1])
axes[0,0].set_title('high cloud area outgoing longwave',fontsize = 14)
axes[0,1].set_title('high cloud area outgoing shortwave',fontsize = 14)
axes[1,0].set_title('low cloud area outgoing longwave',fontsize = 14)
axes[1,1].set_title('low cloud area outgoing shortwave',fontsize = 14)
plt.tight_layout()
The global mean values of shortwave and longwave radiation were not composited in high and low cloud regions. And you did not answer the question. 2 point were deducted for 2.5.
print('high cloud longwave:',np.mean(ds.toa_lw_all_mon.mean(dim='time')))
print('high cloud shortwave:',np.mean(ds.toa_sw_all_mon.mean(dim='time')))
print('low cloud longwave:',np.mean(ds.toa_lw_all_mon.mean(dim='time')))
print('low cloud shortwave:',np.mean(ds.toa_sw_all_mon.mean(dim='time')))
high cloud longwave: <xarray.DataArray 'toa_lw_all_mon' ()> array(224.75517, dtype=float32) high cloud shortwave: <xarray.DataArray 'toa_sw_all_mon' ()> array(102.30433, dtype=float32) low cloud longwave: <xarray.DataArray 'toa_lw_all_mon' ()> array(224.75517, dtype=float32) low cloud shortwave: <xarray.DataArray 'toa_sw_all_mon' ()> array(102.30433, dtype=float32)
import numpy as np
import pandas as pd
import xarray as xr
from matplotlib import pyplot as plt
import nc_time_axis
get_ipython().run_line_magic('matplotlib', 'inline')
ds = xr.open_dataset('air temperature anomaly 2012.nc', engine = 'netcdf4')
group_data = ds.air.groupby('time.month')
air_anom = group_data - group_data.mean(dim = 'time')
new_air_anom = air_anom.sel(lon = slice(190, 240), lat = slice(-30, 30))
new_air_anom = new_air_anom.mean(dim = {'lon', 'lat'})
time = pd.date_range(start = '2012-01-01', periods = 366, freq = 'd')
fig,ax = plt.subplots(1, 1, figsize = (8, 5), dpi = 300)
ax.plot(time, new_air_anom, color = 'k')
ax.set_ylabel('Anomaly Degrees C', color = 'k', fontsize = 15)
ax.set_xlabel('Time', color = 'k', fontsize = 15)
ax.set_title("sigma 0.995", fontsize = 20)
ax.grid(linestyle = '--',linewidth = 0.3, alpha = 0.5, color = 'k')
ax.hlines(y = 0.5, xmin = time[0], xmax = time[-1], color = 'b',linestyles = '--',lw = 0.5,label = 'upper 0.5')
ax.hlines(y = -0.5, xmin = time[0], xmax = time[-1], color = 'r',linestyles = '--',lw = 0.5,label = 'lower 0.5')
ax.hlines(y = 0, xmin = time[0], xmax = time[-1], color = 'k', linestyles = 'solid', lw = 1, label = 'normal')
ax.set_ylim(-2, 2)
ax.legend(loc = 'best', fontsize = 12)
ax.fill_between(time, 0, line_air_anom, where = (line_air_anom > 0), color = 'b')
ax.fill_between(time, 0, line_air_anom, where = (line_air_anom < 0), color = 'r')
/Users/haohuang/miniconda3/envs/ese5023/lib/python3.9/site-packages/xarray/coding/times.py:123: SerializationWarning: Ambiguous reference date string: 1-1-1 00:00:0.0. The first value is assumed to be the year hence will be padded with zeros to remove the ambiguity (the padded reference date string is: 0001-1-1 00:00:0.0). To remove this message, remove the ambiguity by padding your reference date strings with zeros. warnings.warn(warning_msg, SerializationWarning)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /var/folders/qy/ngsg7cz10ys7fn_5n46kknmr0000gn/T/ipykernel_9572/1915798351.py in <module> 23 ax.legend(loc = 'best', fontsize = 12) 24 ---> 25 ax.fill_between(time, 0, line_air_anom, where = (line_air_anom > 0), color = 'b') 26 ax.fill_between(time, 0, line_air_anom, where = (line_air_anom < 0), color = 'r') NameError: name 'line_air_anom' is not defined
There is no line_air_anom. And I also could not find out what does this figure look like. 2 points were deducted.
fig, axes = plt.subplots(2, 3, figsize = (16, 9), sharex = False, sharey = False, dpi = 400)
ds_air_Nov = ds.air.sel(time = slice('2012-11-01', '2012-11-30'))
ds_air_June = ds.air.sel(time = slice('2012-06-01', '2012-06-30'))
ds_air_luan = ds.air.sel(lon = '116', lat = '31', method = 'nearest')
ds_air_day = ds.air.isel(time = -1)
ds_air_Nov.mean('time').plot(ax = axes[0,0])
ds_air_Nov.max('lon').transpose().plot(ax = axes[0,1])
ds_air_day.plot(ax = axes[0, 2])
ds_air_June.mean('time').plot(ax = axes[1,0], cmap = 'jet')
ds_air_June.min('lon').transpose().plot(ax = axes[1,1], cmap = 'jet', alpha = 1)
ds_air_luan.plot(ax = axes[1, 2], c = 'b')
axes[1,2].grid(linestyle = '-.', linewidth = 1, alpha = 0.3)
axes[0,0].set_title('average temp in Nov 2012', fontsize = 16)
axes[0,1].set_title('Nov 2012 max lon', fontsize = 16)
axes[0,2].set_title('2012-12-31', fontsize = 16)
axes[1,0].set_title('average temp in June 2012', fontsize = 16)
axes[1,1].set_title('June 2012 min lon', fontsize = 16)
axes[1,2].set_title('luan 2012 average temp', fontsize = 16)
plt.tight_layout()